package com.example.microserviceeurekauserhystrix.Controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author liuyulong
 * @create 2022-03-23 17:09
 * @create 2022-三月  星期三
 * @project Microservice-SpringCloud_work2_2022_3_16
 */
@RestController
public class UserController {

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/buy/{id}")
    @HystrixCommand(fallbackMethod = "fallbackInfo")
    public String findOrdersByUser(@PathVariable String id) {
        return this.restTemplate.getForObject("http://mircoservice-eureka-product/product/" + id, String.class);
    }

    public String fallbackInfo(@PathVariable String id){
        return "服务不可用，请稍后再试";
    }


}
